$(function () {
    function PMPaidBillView() {
        this.billId = $('#billId').val();
        // 表格ID
        this.dataTable = $("#dataTable");
        this.viewForm = $('#bill-view-form');
        this.viewDiv = $('#bill-view-div');
        this.itemModal = $('#item-modal');
        // 按钮
        // 初始化
        this.init();
    }

    PMPaidBillView.prototype.Constructor = PMPaidBillView;

    PMPaidBillView.prototype.init = function () {
        this.loadTable();
        this.registEvent();
    };

    PMPaidBillView.prototype.loadTable = function () {
        var that = this;
        this.dataTable.dataTable({
            "sAjaxSource": "/pmbill/item/all",
            "aoColumns": [
                {"sWidth": "15%", "sTitle": "费用名称", "sClass": "center", "mData": "costName", "bSortable": false},
                {"sWidth": "15%", "sTitle": "起止日期", "sClass": "center", "mData": "duration", "bSortable": false},
                {"sWidth": "9%", "sTitle": "单价", "sClass": "center", "mData": "unitPrice", "bSortable": false},
                {"sWidth": "9%", "sTitle": "数量", "sClass": "center", "mData": "number", "bSortable": false},
                {"sWidth": "12%", "sTitle": "金额", "sClass": "center", "mData": "amount", "bSortable": false},
                {"sWidth": "12%", "sTitle": "创建时间", "sClass": "center", "mData": "created", "bSortable": false},
                {"sWidth": "14%", "sTitle": "备注", "sClass": "center", "mData": "remark", "bSortable": false}
            ],
            "aLengthMenu": [],
            "aaSorting": [],
            "bPaginate": false,
            "bInfo": false,
            "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                var id = aData["id"];
                if (aData['created']) {
                    $('td:eq(5)', nRow).html(SysTool.Date.formatDate(aData['created'], 'yyyy-MM-dd'));
                }
            },
            "fnServerParams": function (aoData) {
                aoData.push({name: "billId", value: that.billId});
            },
            "fnStateLoaded": function (oSettings, oData) {
//                alert(JSON.stringify(oData));
            }
        });
    };

    PMPaidBillView.prototype.refreshTable = function () {
        this.dataTable.dataTable().fnClearTable();
    };

    PMPaidBillView.prototype.registEvent = function () {
        var that = this;
        $('.date-picker').datepicker({autoclose: true}).next().on(ace.click_event, function () {
            //$(this).prev().focus();
        });

        SysTool.Html.bindEnterClick([], that.$seachr_btn);
    };

    window.PMNeedPayBillItem = new PMPaidBillView();
});